<?php
/**
 * Created by PhpStorm.
 * User: 共赢岛
 * Date: 2024/11/29
 * Time: 9:44
 */

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;

class DebugController extends Controller
{
    public function userDaysRemaining() {
        $user = User::get();

        if ($user) {
            foreach ($user as $key => $value) {
                if (date('Y-m-d H:i:s') > $value->start_at) {
                    $datetime1 = time();
                } else {
                    $datetime1 = strtotime($value->start_at);
                }

                $datetime2 = strtotime($value->end_at);
                $diff = $datetime2 - $datetime1;

                $interval = floor($diff / (60 * 60 * 24));

                $value->days_remaining = $interval;
                $value->save();
            }

            return $this->success('用户数据已处理！');
        } else {
            return $this->failure('暂无用户数据处理！');
        }
    }
}
